import { resolve } from "path";
import { defineConfig } from "vite";
import { viteTinyfy } from "vite-plugin-tinyfy";
import react from "@vitejs/plugin-react-swc";
//import basicSsl from "@vitejs/plugin-basic-ssl";

const BUILD_ENV = process.env.BUILD_ENV;
const isProd = BUILD_ENV === "prod";

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    open: true,
    host: true,
    //https: {},
    port: 4000,
    proxy: {
      "/pro-api": {
        target: `https://${BUILD_ENV}-mobile-api.bankneo.co.id`,
        rewrite: (path: string) => path.replace(/^\/pro-api/, ""),
        changeOrigin: true,
        secure: false,
      },
      "/api": {
        target: `http://localhost:3000/`,
        rewrite: (path: string) => path.replace(/^\/api/, ""),
        changeOrigin: true,
        secure: false,
      },
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
  plugins: [
    //basicSsl(),
    react(),
    viteTinyfy(),
  ],
  build: {
    minify: isProd,
    sourcemap: !isProd,
    rollupOptions: {
      output: {
        manualChunks: {
          react: ["react"],
          reactDom: ["react-dom"],
          reactRouterDom: ["react-router-dom"],
          reactRedux: ["react-redux"],
          reduxjs: ["@reduxjs/toolkit"],
          axios: ["axios"],
        },
      },
    },
  },
  optimizeDeps: {
    include: ["react", "react-dom", "react-router-dom", "react-redux", "@reduxjs/toolkit", "axios"],
  },
});
